<?php
require_once(dirname(__FILE__)."/config.php");
require_once(QFINC."/common.func.php");

//Ȩ����֤
//if(strtolower($_SESSION["qf_admin_id"]) != "admin")
$adminid = $cuserLogin->getUserID();
if(strtolower($adminid) != "admin")
{
	ShowMsg('ֻ�й���Ա�������վ�㣡',"blank.htm");
    exit();
}

if(empty($dopost)) $dopost = '';
if(empty($sid)) $sid = '';

if($dopost != 'save')
{
	//...
	include(QFADMIN.'/templets/add_site.htm');
	exit();
}
else if($dopost=='save')
{
	//if(!isset($sitename)) $sitename = "";
	if(empty($sitename))
	{
		ShowMsg("��վ��Ʋ���Ϊ��!", "-1");
		exit();
	}
	
	//$sql="insert into xxx_table (xxx_date , xxx_datetime) values( curdate(),now() )";
	//$ntime = time();
	//$ntime = date("Y-m-d H:i:s", strtotime("2001-1-1 20:11:11"));
	$ntime = date("Y-m-d H:i:s" ,time());	
	//$siteid = uniqid("s_",true);
 	$query ="";
 	if(empty($sid))
 	{
 		$sid = "s_".md5(uniqid(rand()));//uniqid("s_",true);
 		$query = "INSERT INTO `#@__site` (sid,description,sname,surl,sitestatus,updatetime,updateby,sortno) Values('$sid','$descr','$sitename','$surl','$sitestatus','$ntime','$adminid','999')";
 	}
 	else 
 	{
 		$query = "UPDATE `#@__site` set
 		description='$descr',
 		sname='$sitename',
 		surl='$surl',
 		sitestatus='$sitestatus',
 		updatetime='$ntime',
 		updateby='$adminid' where sid='$sid'";
 	}	

	if(!$dsql->ExecNoneQuery($query))
    {
        $gerr = $dsql->GetError();
        ShowMsg("����ʧ��:".str_replace('"','',$gerr),"-1");
        exit();
    }
    else {
    	redirect("sites.php");
    	//ShowMsg("����ɹ�!","sites.php");
        exit();
    }	   
	
}

